<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends CI_Controller {


	public function index()
	{
    
    $data=array();
		loading($this->db,$this->session,$this->load,"home","index",$data);
	}





	public function get_menu(){
		$roleid=$this->session->userdata("roleid");
		//$roleid=1;
		//echo $roleid;
		$arr=array();
		$all=array();
        $sql="select B.id,B.menu,B.action,B.method,B.type,B.parent,B.icon,A.role_id from `function_to_role` as A,`function` as B where A.`function_id`=B.`id` and A.`role_id`='$roleid' and B.`type`=1 and B.`parent`=-1 order by B.sort ASC";
       $query=$this->db->query($sql);
        $num=$query->num_rows();
        if($num>0){
        	$arrvalue=$query->result_array();
        	foreach ($arrvalue as $key => $value) {
        		$tmpkk=array();
        		$tmpkk['menuid']=$value['id'];
        		$tmpkk['icon']=$value['icon'];
        		$tmpkk['menuname']=$value['menu'];
        		$tmpkk['menus']=array();
        		$parent=$value['id'];
        		$sql2="select B.id,B.menu,B.icon,B.action,B.method,B.type,B.parent,A.role_id from `function_to_role` as A,`function` as B where A.`function_id`=B.`id` and A.`role_id`='$roleid' and B.`type`=1 and B.`parent`='$parent' order by B.sort ASC";
        		$query2=$this->db->query($sql2);
        		$num2=$query2->num_rows();
        		if($num2>0){
	                $aaa=$query2->result_array();
	                foreach ($aaa as $key2 => $value2) {
	                	  $tmp2=array();
                           $tmp2['menuid']=$value2['id'];
			        		$tmp2['icon']=$value2['icon'];
			        		$tmp2['menuname']=$value2['menu'];
			        		$tmp2['url']=site_url()."index.php/".$value2['action']."/".$value2['method'];
	                    $tmpkk['menus'][]=$tmp2;
	                }
                   }
                $all[]=$tmpkk;
                //print_r($all);

                //echo "<br/><br/>";
               $arr=array_merge($arr,$all);
               unset($all);
               unset($tmpkk);
        	}
        }
			$aa="{\"menus\":".json_encode($arr)."}";
			echo $aa;

	}

}
